package com.dyna.mapper;

import com.dyna.core.LambdaQueryWrapperX;
import com.dyna.domain.resp.PageResult;
import com.dyna.foundation.domain.entity.SysRole;
import com.dyna.foundation.domain.req.SysRolePageReq;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable;

import java.util.Collection;
import java.util.List;

/**
* @author zhoucaiwang
*/

@Mapper
public interface SysRoleMapper extends BaseMapperX<SysRole> {

    default PageResult<SysRole> selectPage(SysRolePageReq reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SysRole>()
                .likeIfPresent(SysRole::getName, reqVO.getName())
                .likeIfPresent(SysRole::getCode, reqVO.getCode())
                .eqIfPresent(SysRole::getStatus, reqVO.getStatus())
                .betweenIfPresent(SysRole::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(SysRole::getSort));
    }

    default SysRole selectByName(String name) {
        return selectOne(SysRole::getName, name);
    }

    default SysRole selectByCode(String code) {
        return selectOne(SysRole::getCode, code);
    }

    default List<SysRole> selectListByStatus(@Nullable Collection<Integer> statuses) {
        return selectList(SysRole::getStatus, statuses);
    }

}




